package com.example.demo.controller;

import com.example.demo.jejo.Address;
import com.example.demo.jejo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ResponseController {


    //1.响应字符串
    @RequestMapping("/hello")
    public String StringResponse() {
        return "hello world";
    }

    //2.响应列表
    @RequestMapping("/getAddress")
    public List<User> responseList() {
        ArrayList<User> list = new ArrayList<>();
        User user1 = new User();
        user1.setName("葵花喵");
        user1.setAge(18);
        user1.setAddress(new Address("中国", "四川省", "绵阳市", "江油市"));
        list.add(user1);

        User user2 = new User();
        user2.setName("朱小龙");
        user2.setAge(100);
        user2.setAddress(new Address("中国", "浙江省", "杭州市", "湖州市"));
        list.add(user2);

        return list;
    }

    //3.响应对象
    @RequestMapping("getObject")
    public User getObject(){

        User user = new User();
        user.setName("葵花喵");
        user.setAge(18);
        user.setAddress(new Address("中国", "四川省", "绵阳市", "江油市"));
        return user;
    }


}
